<!DOCTYPE html>
<html style="background: #f7f7f7;">
<head lang="en">
    <meta charset="UTF-8">
    <meta name='apple-touch-fullscreen' content='yes'>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta content="fullscreen=yes,preventMove=no" name="ML-Config">
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>商品详情</title>
    <link rel="stylesheet" href="/style/wei/css/swiper.min.css">
    <link rel="stylesheet" href="/style/css/style1.css?ver=20191206">
    <link rel="stylesheet" type="text/css" href="/style/css/sweet-alert.css"/>
    <script src="/style/js/index/style.js"></script>
    <script type="text/javascript" src="/style/wei/js/jquery.min.js"></script>
    <script src="/style/js/sweet-alert.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/style/new/js/jquery.lazyload.js"></script>
    <script type="text/javascript" src="/style/wei/js/jquery.cookies.js"></script>
    <style>
        .nostock{
            position: absolute;
            top: 0;
            z-index: 999;
            background: #fff;
            width: 2rem;
            height: 2rem;
            line-height: 2rem;
            color: #fff;
            border-radius: 2rem;
            background-color: rgba(235, 41, 148, 0.5)!important;
            filter: Alpha(opacity=50);
            background: #EB2994;
            text-align: center;
            font-size: .5rem;
            margin: 15% auto;
            right: 0;
            left: 0;
        }

        .d_count{ position: relative; }
        .d_count i{ position: absolute;top: -0.1rem;right: -0.10rem;background: #fc1d30;color: #fff;width: 0.4rem;font-size: 0.25rem;text-align: center;border-radius: 0.3rem;}
        .more {
            float: left;
            width: 100%;
            height: auto;
            padding: .2rem 0;
            background: #fff;
        }
        .more .zhekou, .more .sheng {
            margin-left: .2rem;
            float: left;
            width: auto;
            background: #fff;
            border: 1px solid #f7571e;
            color: #f7571e;
            text-align: center;
            padding: 0 .1rem;
            /* line-height: 20px; */
            /* height: 20px; */
            border-radius: 0.12rem;
            /* margin: 0 .2rem 0 0.2rem; */
            font-size: .2rem;
        }
        .more .share {
            float: left;
            width: auto;
            padding: 0 .1rem;
           /* height: .5rem;
            line-height: .5rem;*/
            text-align: center;
            border:1px solid #f7571e;
            color: #f7571e;
            font-size: .2rem;
            border-radius: 0.12rem;
            margin-left: .2rem;
        }
        .more .warehouse {
            float: left;
            width: auto;
            margin: 0 .2rem 0 0;
        }
        .more .warehouse u {
            float: left;
            width: .5rem;
            text-decoration: none;
            border-radius: 0 0 0 5px;
            color: #fff;
            height: 24px;
        }
        .more .warehouse i {
            float: left;
            width: auto;
            background: #fff;
            border: 1px solid #666;
            color: #666;
            font-size: .25rem;
            height: 24px;
            line-height: 24px;
            padding: 0 .1rem;
            border-radius: 0 5px 0 0;
        }
        .more .warehouse.baoshui u {
            border: 1px solid #0080FF;
            background: url(/style/new/images/icon_warehouse.png) no-repeat #0080FF;
            background-size: .4rem .4rem;
            background-position: 2px 0;
        }
        .more .warehouse.baoshui i {
            border: 1px solid #0080FF;
            color: #0080FF;
        }
        .more .warehouse.bendi u {
            border: 1px solid #00C100;
            background: url(/style/new/images/icon_warehouse.png) no-repeat #00C100;
            background-size: .4rem .4rem;
            background-position: 2px 0;
        }
        .more .warehouse.bendi i {
            border: 1px solid #00C100;
            color: #00C100;
        }
        .more .warehouse.haiwai u {
            border: 1px solid #B200B2;
            background: url(/style/new/images/icon_warehouse.png) no-repeat #B200B2;
            background-size: .4rem .4rem;
            background-position: 2px 0;
        }
        .more .warehouse.haiwai i {
            border: 1px solid #B200B2;
            color: #B200B2;
        }
        .spi-top-info .preicebar .collection {
            float: right;
            text-align: center;
            width: 1rem;
            color: #2c2c2c;
            font-size: .25rem;
            line-height: .5rem;
            margin-right: .3rem;
        }
        .goods_tetx{ font-size:0.32rem; line-height: .6rem; }
        .goods_tetx p{ padding: 0 0.2rem;overflow: hidden; }
        /*加入购物车弹窗*/
        .detail_popup{ width: 100%;height: 100%;background: rgba(0,0,0,0.3);position: fixed;top: 0;z-index: 9999; }
        .detail_modal{ padding: 0.25rem;background: #fff;width: 7rem;margin: 0 auto;position: fixed;bottom: 0;z-index: 999;border-top-left-radius: 0.2rem;border-top-right-radius: 0.2rem; }
        .detail_modal_top{ display: flex;align-items: center;margin-bottom: 0.32rem; }
        .detail_modal_top .img1{ width: 1.64rem;height: 1.64rem;border-radius: 0.2rem;margin-right: 0.2rem; }
        .modal_top_center{ width: 4.5rem;display: inline-block; }
        .modal_top_center h3{ display: flex;align-items: center;color: #ca342e; }
        .modal_top_center h3 i{ font-size: 0.25rem }
        .modal_top_center h3 b{ font-size: 0.38rem }
        .modal_top_center h4{ font-size: 0.22rem;color: #666; }
        .detail_modal_list{ margin-bottom: 0.32rem;overflow: hidden; }
        .detail_modal_list h3{ font-size: 0.26rem;color: #878787;margin-bottom: 0.18rem; }
        .detail_modal_list ul li{ padding: 0.1rem 0.3rem;background: #f4f4f4;color: #646464;font-size: 0.26rem;text-align: center;display: flex;justify-content: center;align-items: center;border-radius: 0.15rem;margin-right: 0.2rem;float: left;border: 0.01rem solid transparent;margin-bottom: 0.2rem; }
        .detail_modal_list ul li.on{ background: #fdf6f6;color: #ca342e;border: 0.01rem solid#ca342e; }

        .spinner { width: 2rem; overflow: hidden; display: flex; align-items: center; -moz-box-shadow: 0 3px 3px -4px #aaa;}
        .spinner button, .spinner .value { text-align: center; display: block; float: left; margin: 0;}
        .spinner button { border: none; width: 23px; color: #474747; padding: 0; font-size: 0.5rem; outline: none; background: #fff;}
        .spinner .decrease[disabled] { background-position: 0 -75px; cursor: default;}
        .spinner .increase { cursor: pointer; background:#fff;}
        .spinner .value { width: 0.8rem; background: #f4f4f4; padding: 0.08rem 0; border-radius: 0.1rem; margin: 0 0.2rem; color: #464646;}
        .detail_modal_btn{ width: 7rem;margin: 1.2rem auto 0.2rem;text-align: center;background: #ca342e;font-size: 0.26rem;color: #fff;border-radius: 0.6rem;line-height: 0.76rem;height: 0.76rem;border: none; }
        .detail_close{ width: 0.19rem;height: 0.19rem;    position: absolute;right: 0.3rem;top: 0.27rem; }
        .modal_top_center h2{ font-size: 0.28rem;color: #333;margin-bottom: 0.1rem;display: -webkit-box;
            overflow: hidden;
            -webkit-box-orient: vertical;
            text-overflow: ellipsis;
            -webkit-line-clamp: 2; }
        .detail_scroll{ height: 5rem;overflow-y: scroll;width: 100%; }
    </style>
</head>
<body>
<div id="loutinav">
    <a href="javascript:history.back(-1);" class="d_back"><img src="/style/images/index/d_2.png" alt=""></a>
    <ul>
        <li class="active"><span>商品</span> </li>
      <!--  <li><span>评价</span> </li>-->
        <li><span>详情</span> </li>
    </ul>
    <!--<a href="#" class="d_fx"><img src="/style/images/index/d_3.png" alt=""></a>-->
</div>
<div id="header">
    <div class="index_box jz640">
        <div class="detail_twoBox">
            <div class="detail_ban">
                <ul class="detail_two clearfix">
                    <?php
                    $default_share = '';
                   // $cnt = count($this->data['docids']);
                    if($this->data['docids'] && $this->data['docs']){
                    foreach($this->data['docids'] as $r){

                    if($default_share == "")
                    {
                        $default_share = $this->data['docs'][$r];
                    }
                    ?>
                    <li><a href='#'><img src="<?=$this->data['docs'][$r];?>" alt='ban2' ></a></li>
                    <?php
                        }
                    }
                    ?>
                </ul>
            </div>
            <ul class="num"></ul>
        </div>
    </div>
    <div class="header_top">
        <a href="javascript:history.back(-1);" class="d_back"><img src="/style/images/index/d_2.png" alt=""></a>
      <!--  <a href="#" class="d_fx"><img src="/style/images/index/d_3.png" alt=""></a>-->
    </div>
    <?php
    if($this->data['stock_number'] <1)
    {
        echo '<div class="nostock">补货中</div>';
    }
    ?>
</div>
<div id="main">
    <div class="louti">
        <div class="d_bk">
            <div class="d_blcontent">
                <h3>
                    <?php
                    if($this->data['shop_price']>0)
                    {
                        echo '<i>￥</i><em>'.$this->data['shop_price'].'</em>';
                    }
                    elseif($this->data['ximi_price'])
                    {
                        echo '<i></i><em>'.($this->data['ximi_price']*1).'硒米</em>';
                    }
                    ?>


                </h3>
                <?php
                if($this->data['market_price']>0)
                {
                    echo '<h4>￥'.$this->data['market_price'].'</h4>';
                }
                ?>
                
            </div>
            <p><!--距结束<em>30:17:34</em>--></p>
            <!--<div class="d_nav">
            <img src="/style/images/index/d_5.png" alt="" class="d_v">
                <h3><i>开通掌柜 自购省</i><em>￥15.00</em><i>分享赚</i><em>￥15.00</em></h3>
                <a href="#"><i>去开通</i> <img src="images/d_6.png" alt=""></a>
            </div>-->
        </div>
        <div class="d_bar">
            <h4><?=$this->data['goods_name'];?></h4>
          <!--  <h5>累计热销<?/*=$this->data['sales_count'];*/?>件</h5>-->
        </div>

        <div class="d_by">
            <ul>
                <li style="display:flex;align-items:center;">

                    <h3 style="width:0.84rem;font-size: 0.24rem; color: #9c9c9c;">促销</h3>
                    <a href="#" style="width:100%">
                    <div class="more">
                        <?php
                        if($this->data['price_me']>0){
                            echo '<div class="zhekou">返'.($this->data['price_me'] * 1).'</div>';
                        }
                        if($this->data['coupon_price'] > 0)
                        {
                            echo '<div class="sheng">抵券'.$this->data['coupon_price'].'</div>';
                        }

                        if($this->data['price_level1']>0 && $this->member_level>=1)
                        {
                            echo '<div class="share">推广赚'.($this->data['price_level1'] * 1).'</div>';
                        }
                        ?>
                    </div>
                    </a>

                </li>
                <li>

                    <a href="#"><b style="font-size: 0.26rem;">1<?=$this->data['goods_unit']?></b></a>
                    <h3><i>已选</i></h3>

                </li>
                <li>

                    <h3><i>配送</i><b></b></h3>
                    <a href="#"><em><?=$this->data['is_free_shipping']?"包邮":"8元";?></em></a>
                    <div style="color: #333; font-size: .25rem;  float: right; margin:.2rem 0 0 1rem;">
                    <?=$this->data['express_setting']['no_sale_str']!="" ? $this->data['express_setting']['no_sale_str'].'<br /><br />' : '';?><?=$this->data['express_setting']['extra_money_str']!="" ? $this->data['express_setting']['extra_money_str'].'<br />' : '';?></div>
                </li>

            </ul>
        </div>
    </div>
<!--    <div class="louti">
        <div class="d_pj">
            <dl>
                <dt>
                    <h3><span>商品评价</span><i>（5）</i></h3>
                    <a href="#"><i>查看全部</i><img src="images/d_8.png" alt=""></a>
                </dt>
                <dd>
                    <div class="d_top">
                        <img src="images/d_9.png" alt="" class="d_top_img">
                        <div class="d_top_right">
                            <h3>神秘用户</h3>
                            <h4>
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                            </h4>
                        </div>
                    </div>
                    <p>货真价实，挺好的</p>
                </dd>
                <dd>
                    <div class="d_top">
                        <img src="images/d_9.png" alt="" class="d_top_img">
                        <div class="d_top_right">
                            <h3>神秘用户</h3>
                            <h4>
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                            </h4>
                        </div>
                    </div>
                    <p>货真价实，挺好的</p>
                </dd>
            </dl>
        </div>
    </div>-->
    <div class="louti">
        <!-- <div class="d_xq">
            <div class="d_xq_left">
                <img src="<?=$this->data['supplier']['headimgurl'] !="" ?$this->data['supplier']['headimgurl']:'/style/images/index/d_9.png';?>" alt="">
                <i><?=$this->data['supplier']['supplier']?></i>
            </div>
            <a href="#" class="d_xq_right">
                进店逛逛
            </a>
        </div> -->
        <div class="goods_tetx">
            <?php
            $desc = htmlspecialchars_decode($this->data['goods_desc']);
            $desc = str_replace("<img src=","<img class=\"lazyimg\" src=\"/style/images/lazycover.jpg?ver=20191109\" data-original=",$desc);
            echo $desc;
            ?>
        </div>
    </div>
</div>
<div class="d_footer">
    <ul class="d_footer_left">
        <li class="collection <?=$this->data['collection']>0?"d_on":'';?>"><a href="javascript:;"><img src="/style/images/index/d_<?=$this->data['collection']>0?15:11;?>.png" alt=""><span>收藏</span></a></li>
        <li><a href="#"><img src="/style/images/index/d_12.png" alt=""><span>客服</span></a></li>
        <li class="d_count"><a href="/cart/cart"><img src="/style/images/index/d_13.png" alt=""><span>购物车</span></a><i><?=$this->cartnum?></i></li>
    </ul>
    <div class="d_footer_right">
        <i onClick="_chuanzhi(0)">加入购物车</i>
        <span onClick="_chuanzhi(1)">立即购买</span>
    </div>
</div>
<!--加入购物车弹窗-->
<!--<div class="add_popup">-->
<!--    <div class="add_view">-->
<!--        <div class="add_top">-->
<!--            <img src="" alt="">-->
<!--            <div></div>-->
<!--        </div>-->
<!--        <div class="add_main"></div>-->
<!--    </div>-->
<!--</div>-->
<div class="detail_popup" style=" display: none; ">
    <div class="detail_modal">
        <div class="detail_modal_top">
            <img src="<?=$this->data['pic_url']?>" alt="" class="img1">
            <div class="modal_top_center">
                <h2><?=$this->data['goods_name']?></h2>
                <h3><i>¥</i><b class="js_shop_price" data-shop_price="<?=$this->data['shop_price']?>"><?=$this->data['shop_price']?></b></h3>
                <h4 class="js_stock_number" data-stock_number="<?=$this->data['stock_number']?>">库存 <?=$this->data['stock_number']?></h4>
            </div>
            <img src="/style/images/cc.jpg" alt="" class="detail_close">
        </div>
        <div class="detail_scroll">
            <?php foreach ($this->data['spec'] as $key => $value) :?>
            <div class="detail_modal_list tab_list_parent">
                <h3><?=$value['name']?></h3>
                <ul class="tab_list">
                    <?php foreach ($value['child'] as $k => $val) :?>
                    <li class="tab_list_li" data-caid="<?=$val['caid']?>"><?=$val['name']?></li>
                    <?php endforeach;?>
                </ul>
            </div>
            <?php endforeach;?>
            
            <div class="detail_modal_list">
                <h3>数量</h3>
                <div>
                    <div class="spinner">
                        <button class="decrease _dec cursor">-</button>
                        <input type="text" class="spinnerExample value passive" value="1">
                        <button class="increase _add cursor">+</button>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" class="js_stock_id" name="stock_id" value="0">
        <input type="hidden" class="js_zhi" value="0">
        <button class="detail_modal_btn" onClick="_addtocart(<?php echo $this->data['goods_id']?>)">确定</button>
    </div>
</div>
<script>
    //减
    $("body").on("click","._dec",function(){
        var n = 0;
        var ise = $(this).siblings("input").eq(0).val();
        var gc_id = $(this).siblings("input").eq(1).val();
        if(parseInt(ise) <= 1){
            n = 1;
            $(this).siblings("input").eq(0).val(n)
            $(this).siblings("input").eq(1).val(n)
        }else{
            n =parseInt(ise)-1;
            $(this).siblings("input").eq(0).val(n)
            $(this).siblings("input").eq(1).val(n)
        }

        // _cart_number($(this).siblings("input").eq(1).attr("data-cartid"),n);
        _refresh_price();

    })
    //加
    $("body").on("click","._add",function(){
        var ise = $(this).siblings("input").eq(0).val();
        var _max_stocknumber = parseInt($(this).siblings("input").eq(1).attr("data-stocknumber") );

        var n = parseInt(ise)+1;
        if(n>_max_stocknumber) n =_max_stocknumber;
        $(this).siblings("input").eq(0).val(n)
        $(this).siblings("input").eq(1).val(n)

        // _cart_number($(this).siblings("input").eq(1).attr("data-cartid"),n);
        _refresh_price();

    })

function _refresh_price()
{
    var gm_number = parseInt($('.passive').val());
    var js_shop_price = $('.js_shop_price').data('shop_price');
    $('.js_shop_price').html((gm_number*js_shop_price).toFixed(2));
}

//js数组去重
function unique(arr){            
    for(var i=0; i<arr.length; i++){
        for(var j=i+1; j<arr.length; j++){
            if(arr[i]==arr[j]){         //第一个等同于第二个，splice方法删除第二个
                arr.splice(j,1);
                j--;
            }
        }
    }
    return arr;
}
function _chuanzhi(zhi){
    $(".js_zhi").val(zhi);
    $(".detail_popup").show();

}
    $(function () {
        $(".detail_close").click(function () {
            $(".detail_popup").hide();
        })
        // $(".d_footer_right i").click(function () {
        //     $(".detail_popup").show();
        // });
        // $(".d_footer_right span").click(function () {
        //     $(".detail_popup").css("display","block");
        // });
    })
    $(function () {
        var spec_cnt = "<?= count($this->data['spec']) ?>";
        var goods_id = '<?= $this->data['goods_id']?>';
        var caid_str = [];

        $(".tab_list li").click(function () {
            $(this).addClass("on").siblings().removeClass("on");

            caid_str = [];
            $(".tab_list_li").each(function(){
                if($(this).hasClass("on")){
                    caid_str.push($(this).data("caid"));
                }
            });
            caid_str_value = unique(caid_str).sort().toString();

            console.log(caid_str_value);

            var on_length = $('.on').length;
            if (on_length == spec_cnt) {
                
                console.log('请求');
                $.post("/index/ajax",
                {
                    "act":"spec",
                    "goods_id":goods_id,
                    "caid_str":caid_str_value,
                    "mr":Math.random()
                },function(json){
                    console.log(json);
                    if(json.code==200)
                    {
                        $('.img1').attr('src',json.data.pic_url);
                        $('.js_shop_price').attr('data-shop_price',json.data.goods_price);
                        $('.js_shop_price').html(json.data.goods_price);
                        $('.js_stock_number').attr('data-stock_number',json.data.goods_number);
                        $('.js_stock_number').html('库存 '+json.data.goods_number);
                        $('.js_stock_id').val(json.data.stock_id);
                    }
                },"json");
            }
            
            // var index = $(this).index();
            // $("")
        })
    })
    var _added = false,
        _goodsid=<?=$this->data['goods_id']?>,
        _goods_number = <?= $this->data['stock_number']?:0;?>,
        _g_top = 0;
    $(function(){
        if(_goods_number < 1)
        {
            $(".d_footer_right").addClass("d_footer_on");
        }

        $(".lazyimg").lazyload({
            threshold : 150,
            placeholder : "/style/images/lazycover.jpg",
            failurelimit : 4
        });
        var detail_ban=$('.detail_two');
        var detail_ban_li=$('.detail_two li');
        var boxW=$(".detail_twoBox").width();

        var len=detail_ban_li.length+1;
        function startMove(){
            var i=0;
            var timer=null;
            detail_ban.css({width:len*boxW});//设置ban宽度
            detail_ban_li.css({width:100/len+"%"});//设置li宽度
            for (var j = 0; j < len-1; j++) {  //创建圆点
                $('.num').append('<li></li>')
            }
            $('.num li').first().addClass('active'); //给第一个圆点添加样式

            var firstimg=detail_ban_li.first().clone(); //复制第一张图片
            detail_ban.append(firstimg); //将第一张图片放到最后一张图片后，设置ul的宽度为图片张数*图片宽度
            //判断左右滑动切换
            detail_ban.on("touchstart", function(e) {
                //                            e.preventDefault();
                startX = e.originalEvent.changedTouches[0].pageX;
                //                            e.stopPropagation();
                return false;
            });
            detail_ban.on("touchend", function(e) {
                //                            e.preventDefault();
                //                            e.stopPropagation();
                moveEndX = e.originalEvent.changedTouches[0].pageX,
                    X = moveEndX - startX;
                if ( X > 0 ) {
                    clearInterval(timer);
                    i--;
                    if (i==-1) {
                        i=detail_ban_li.length-2;
                        detail_ban.css({left:-(len-1)*boxW});
                    }
                    detail_ban.stop().animate({left:-i*boxW},300);
                    $('.num li').eq(i).addClass('active').siblings().removeClass('active');
                }
                else if ( X < 0 ) {
                    clearInterval(timer);
                    i++;
                    if (i==len) {
                        i=1; //这里不是i=0
                        detail_ban.css({left:0}); //保证无缝轮播，设置left值
                    };
                    detail_ban.stop().animate({left:-i*boxW},300);
                    if (i==len-1) {   //设置小圆点指示
                        $('.num li').eq(0).addClass('active').siblings().removeClass('active');
                    }else{
                        $('.num li').eq(i).addClass('active').siblings().removeClass('active');
                    }
                }
                timer=setInterval(function(){
                    ss();
                },3000);
                return false;
            });
            //定时器自动播放
            timer=setInterval(function(){
                autoMove();
            },2500);
            function autoMove(){
                i++;
                if (i==len) {
                    i=1;
                    detail_ban.css({left:0});
                };
                detail_ban.stop().animate({left:-i*boxW},300);
                if (i==len-1) {
                    $('.num li').eq(0).addClass('active').siblings().removeClass('active');
                }else{
                    $('.num li').eq(i).addClass('active').siblings().removeClass('active');
                }
            }
        }
        //主要用于当调整浏览器窗口的大小时文档也相应调整
        $(window).resize(function() {
            boxW=$(".detail_twoBox").width();//获取改变后的窗口大小
            detail_ban.css({width:len*boxW});//设置ban外边框宽度
            detail_ban_li.css({width:100/len+"%"});//设置li宽度
        });
        startMove();//启动js
        //$(".cont img").removeAttr("height").removeAttr("width").css({"width":"100%","height":"auto"});
        //1.楼梯什么时候显示，800px scroll--->scrollTop
        $(window).on('scroll',function(){
            var $scroll=$(this).scrollTop();
            if($scroll>=100){
                $('#loutinav').show();
            }else{
                $('#loutinav').hide();
            }

            //4.拖动滚轮，对应的楼梯样式进行匹配
            $('.louti').each(function(){
                var $loutitop=$('.louti').eq($(this).index()).offset().top+100;
                //console.log($loutitop);
                if($loutitop>$scroll){//楼层的top大于滚动条的距离
                    $('#loutinav li').removeClass('active');
                    $('#loutinav li').eq($(this).index()).addClass('active');
                    return false;//中断循环
                }
            });
        });
        //2.获取每个楼梯的offset().top,点击楼梯让对应的内容模块移动到对应的位置  offset().left
        var $loutili=$('#loutinav li').not('.last');
        $loutili.on('click',function(){
            $(this).addClass('active').siblings('li').removeClass('active');
            var $loutitop=$('.louti').eq($(this).index()).offset().top;
            //获取每个楼梯的offsetTop值
            $('html,body').animate({//$('html,body')兼容问题body属于chrome
                scrollTop:$loutitop
            })
        });
        //3.回到顶部
        $('.last').on('click',function(){
            $('html,body').animate({//$('html,body')兼容问题body属于chrome
                scrollTop:0
            })
        });
    })

    // 收藏
    $(".collection").on("click",function(){


        $.post("/index/ajax",
            {
                "act":"collection",
                "goods_id":_goodsid,
                "mr":Math.random()
            },function(json){
                console.log(json);
                if(json.code==200)
                {
                    if(json.result ==1)
                    {
                        $(".collection img").attr("src","/style/images/index/d_15.png");
                        $(".collection" ).addClass("d_on");

                    }
                    else
                    {
                        $(".collection img").attr("src","/style/images/index/d_11.png");
                        $(".collection").removeClass("d_on");

                    }
                }
            },"json");

    });

    function _addtocart(goods_id){
        var stock_id = $('.js_stock_id').val();
        var goods_number = parseInt($('.passive').val());
        var goto = $(".js_zhi").val();
        var js_stock_number = $('.js_stock_number').data('stock_number');
        // console.log(goto);return;
        if (js_stock_number == 0) {
            swal("商品补货中");return;
        }

        if(_goods_number > 0){
            $.post("/cart/cart_ajax",
                {
                    "goods_id":goods_id,
                    "goods_number":goods_number,
                    "stock_id":stock_id,
                    "mr":Math.random()
                },
                function(json){
                    if(json.code == 200) {
                        _added = true;
                        if (goto == 1)
                        {
                            window.location.href = '/cart/cart';
                        }
                        else
                        {
                            $('.detail_popup').hide();
                            swal('添加到购物车成功', false, "success");

                            if(json.cartnum>0)
                            {
                                if( $("#cartStatus span").hasClass("cartnum"))
                                {
                                    $("#cartStatus span").html(json.cartnum);
                                }
                                else
                                {
                                    $("#cartStatus img").before('<span class="cartnum">'+json.cartnum+'</span>')
                                }
                            }
                        }
                    }
                    else if(json.code==780) swal("商品补货中");
                    else if(json.code==781) swal("商品补货中");
                    else if(json.code==782) swal("已超过限购数量");
                    else if(json.code==783) swal("商品补货中");
                    else if(json.code==785) swal("已超过限购数量");
                    else if(json.code==990) swal("请选择商品规格");
                    else if(json.code==800) window.location.href = '/passport/signin';
                    else swal("加入购物车失败，请重试"+msg);

                },"json");
        }
    }
</script>


<?php
if($this->JSAPI){

    if($default_share == "")
    {
        $default_share = 'http://'.$_SERVER['HTTP_HOST'].'/style/wei/images/tuijian/tj_logo_big2.jpg';
    }
    ?>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script>
        wx.config({
            appId: '<?=$this->JSAPI['appId'];?>',
            timestamp: '<?=$this->JSAPI['timestamp'];?>',
            nonceStr: '<?=$this->JSAPI['nonceStr'];?>',
            signature: '<?=$this->JSAPI['signature'];?>',
            jsApiList: [
                'onMenuShareTimeline',
                'onMenuShareAppMessage'
            ]
        });
        wx.checkJsApi({
            jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'],
            success: function(res) {
            }
        });
        wx.ready(function () {
            wx.onMenuShareAppMessage({
                title: '<?=$this->data['goods_name'];?> - 西海良品',
                desc: '绿色富硒、好吃不贵的优质农产品，自购省钱、分享返钱，欢迎加盟...',
                link: '<?=$this->JSAPI['url'];?>',
                imgUrl: '<?=$default_share;?>',
                type: 'link',
                dataUrl: '',
                success: function () {
                },
                cancel: function () {
                }
            });

            // 分享到朋友圈
            wx.onMenuShareTimeline({
                title: '<?=$this->data['goods_name'];?> - 西海良品',
                link: '<?=$this->JSAPI['url'];?>',
                imgUrl: '<?=$default_share;?>',
                success: function () {
                },
                cancel: function () {
                }
            });

        });
    </script>
    <?
}
?>
</body>
</html>